package com.icoolkj.learn.juc.future;

import com.icoolkj.learn.juc.base.utils.SleepTools;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.CompletableFuture;

/**
 * @author icoolkj
 * @version 1.0
 * @description
 * @createDate 2025/03/05 16:43
 */
@Slf4j
public class CFDemo7 {
    public static void main(String[] args) {
        CompletableFuture<String> future1 = CompletableFuture.supplyAsync(() -> {
            log.info("T1: 查询商品基本信息...");
            SleepTools.second(1);
            return "T1，商品基本信息查询成功";
        });

        CompletableFuture<String> future2 = CompletableFuture.supplyAsync(() -> {
            log.info("T2: 查询商品价格信息...");
            SleepTools.second(1);
            return "T2，商品价格信息查询成功";
        });

        CompletableFuture<String> future3 = CompletableFuture.supplyAsync(() -> {
            log.info("T3: 查询商品库存信息...");
            SleepTools.second(5);
            return "T3，商品库存信息查询成功";
        });

        CompletableFuture<String> future4 = CompletableFuture.supplyAsync(() -> {
            log.info("T4: 查询商品图片信息...");
            SleepTools.milliseconds(500);
            return "T4，商品图片信息查询成功";
        });

        CompletableFuture<String> future5 = CompletableFuture.supplyAsync(() -> {
            log.info("T5: 查询商品销售信息...");
            SleepTools.milliseconds(500);
            return "T5，商品销售信息查询成功";
        });

        CompletableFuture<Void> all = CompletableFuture.allOf(future1, future2, future3, future4, future5);
        all.join();

    }

}
